#ifndef __IBOUNDINGBOX_H__
#define __IBOUNDINGBOX_H__

#include "CTypes.h"
#include "IDrawableFace.h"

class IBoundingBox
{
vector3dvpos Center;
vector3dvpos Len;
public:
	IBoundingBox()			{}
	virtual ~IBoundingBox()	{}

	vector3dvpos &Getdimension()	{	return Len;		}
	vector3dvpos &GetPosition()		{	return Center;	}

	void SetBoundingBox(std::vector<IDrawableFace*> &df)
	{
		vPos Left = 0.0;
		bool LeftSetted = false;
		vPos Right = 0.0;
		bool RightSetted = false;
		vPos Up = 0.0;
		bool UpSetted = false;
		vPos Down = 0.0;
		bool DownSetted = false;
		vPos Back = 0.0;
		bool BackSetted = false;
		vPos Front = 0.0;
		bool FrontSetted = false;
		for (u32 i=0;i<df.size();i++)
		{
			for (u32 j=0;j<df[i]->GetNumVectors();j++)
			{
				vector3dvpos v(df[i]->GetVector(j));
				if (v.X < Left || !LeftSetted)
				{
					Left = v.X;
					LeftSetted = true;
				}
				if (v.X > Right || !RightSetted)
				{
					Right = v.X;
					RightSetted = true;
				}
				if (v.Y > Up || !UpSetted)
				{
					Up = v.Y;
					UpSetted = true;
				}
				if (v.Y < Down || !DownSetted)
				{
					Down = v.Y;
					DownSetted = true;
				}
				if (v.Z < Front || !FrontSetted)
				{
					Front = v.Z;
					FrontSetted = true;
				}
				if (v.Z > Back || !BackSetted)
				{
					Back = v.Z;
					BackSetted = true;
				}
			}
		}

		Len.X = Right - Left;
		Len.Y = Up - Down;
		Len.Z = Back - Front;
		Center.X = (vPos)(Left + (Len.X / 2.0));
		Center.Y = (vPos)(Down + (Len.Y / 2.0));
		Center.Z = (vPos)(Back + (Len.Z / 2.0));
	}
};

#endif
